package com.jichangxiu.framework.factory;

import cn.hutool.core.util.ObjectUtil;
import com.jichangxiu.common.context.JcxContext;
import com.jichangxiu.common.entity.bo.JcxContextEntity;
import com.jichangxiu.common.entity.rule.LogRule;
import com.jichangxiu.framework.service.LogRuleService;
import com.jichangxiu.framework.utils.LogRuleUtils;

import java.util.TimerTask;

public class LogRuleAsyncFactory {

    public static <T> TimerTask recordLogRule(LogRuleService logRuleService, LogRule logRule) {
        JcxContextEntity jcxContextEntity = JcxContext.getJcxContextEntity();
        return new TimerTask() {
            @Override
            public void run() {
                // 插入数据
                if (ObjectUtil.isNotEmpty(jcxContextEntity) && ObjectUtil.isNotEmpty(logRuleService) && ObjectUtil.isNotEmpty(logRule)) {
                    LogRuleUtils.fillLocation(logRule);
                    logRuleService.saveLogRule(jcxContextEntity, logRule);
                }
            }
        };
    }

}
